package algotithm.leetcode.dp.hot.test198;

/**
 * @author zhouyanxiang
 * @Date 2021-02-2021/2/9-22:09
 * @Title 198. 打家劫舍
 * @URL https://leetcode-cn.com/problems/house-robber/
 */
public class Solution {

    public static void main(String[] args) {
        Solution solution = new Solution();
        int[] num = {1,2,3,1};
        int i = solution.rob(num);
        System.out.println(i);
    }

    public int rob(int[] num) {
        if (num == null || num.length == 0) {
            return 0;
        }
        int[] dp = new int[num.length];
        dp[0] = num[0];
        dp[1] = Math.max(num[0],num[1]);
        for (int i = 2; i < num.length; i++) {
            dp[i] = Math.max(dp[i-2] + num[i],dp[i-1]);
        }
        return dp[num.length - 1];
    }

}
